#include	"ParseCsvWarning.hpp"
#include	"SubWinWarning.hpp"

SubWinWarning::SubWinWarning(unsigned int heightWinCode, unsigned int widthWinCode, WINDOW *winCode)
{
  (void)widthWinCode;
  this->_height = heightWinCode - 2;
  this->_width = 7;
  this->_win = derwin(winCode, this->_height, this->_width, 1, 1);
  box(this->_win, 0, 0);
  wrefresh(this->_win);
}

SubWinWarning::~SubWinWarning()
{
  
}

void	SubWinWarning::setContentWin(const char *name_file, int size)
{
  //open / read File source code
  this->_fileTree = new ContentFile(name_file);

  ParseCsvWarning parse(this->_fileTree->getList(), size);
  
  //open file source code
  this->_scrollText = new ScrollTextWarning(parse.getListFlags(), this->_height, this->_width, this->_win);
}

void	SubWinWarning::checkEvent(int event)
{
  if (event == KEY_DOWN)
    this->_scrollText->cursorDown();
  else if (event == KEY_UP)
    this->_scrollText->cursorUp();
  else if (event == KEY_RIGHT)
    this->_scrollText->cursorRight();
  else if (event == KEY_LEFT)
    this->_scrollText->cursorLeft();
}

void	SubWinWarning::update(bool focus)
{
  box(this->_win, 0, 0);
  this->_scrollText->update();
}
